﻿using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace Editor.Gmx.AutoGroup
{
    [AttributeUsage(AttributeTargets.Field)]
    public class LabelAttribute : PropertyAttribute
    {
        public string Label { get; private set; }

        public LabelAttribute(string label)
        {
            Label = label;
        }
    }
}

#if UNITY_EDITOR
namespace Editor.Gmx.AutoGroup
{
    [CustomPropertyDrawer(typeof(LabelAttribute))]
    public class LabelAttributeDrawer : PropertyDrawer
    {
        private LabelAttribute Attribute => _attribute ?? (_attribute = attribute as LabelAttribute);

        private LabelAttribute _attribute;

        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var guiContent = new GUIContent(Attribute.Label);
            EditorGUI.PropertyField(position, property, guiContent, true);
        }
    }
}
#endif